home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 050a / bfmt139.zip / BFMT.CPP next >
C/C++ Source or Header  |  1993-04-28  |  22KB  |  760 lines

  1.  
  2. /*
  3.     want to edit stdin and output stdout
  4.     output either justified or left aligned or right aligned
  5.     centered or adjusted (c++ mode)
  6.     user specified width (of character field only), inherit
  7.     word spacing, all lines as paragraphs, specify spacing etc
  8.  
  9.     bfmt -fl -w40
  10.  
  11.  
  12.     plan :
  13.         get line of input and next (flag if no more)
  14.         if new para reset whitespace
  15.         else separate into words and spaces
  16.         pass words and spaces to format type
  17.  
  18.         format type :
  19.             arrange words and spaces
  20.             output to cout
  21.  
  22.  
  23. history :
  24.         1.33 bug in editing paragraph with ^Z on last line
  25.         13/4/93 fixed in version 1.34
  26.  
  27.     15/4/93 fixed bug that deleted words if paragraph too big
  28.         in version 1.37
  29.  
  30.         18/4/93 make last line in justified paragraph unfmt. (1.38)
  31.  
  32.     27/4/93 tried to convert to SunOS c++ ,re suggestion Yan Xu
  33.  
  34.     28/4/93 tested, done and improved by  Yan Xu
  35.         slight modifications by me (1.39)
  36.         to fix error in max_words_per_line
  37. */
  38.  
  39. // --------------------------------------------------------------
  40.  
  41. #include <time.h>
  42. #include <ctype.h>
  43. #include <iostream.h>
  44. #include <fstream.h>
  45. #include <iomanip.h>
  46. #include <stdlib.h>
  47. #include <string.h>
  48.  
  49. #define VERSION "1.39"
  50. #define MAX_LINE_LEN 160
  51. #define MAX_NUM_WORDS 80
  52. #define MAX_WORD_SZ   80
  53. #define WNUM_OFFSET   30
  54. #define MIN_WIDTH     10
  55. #define MAX_SP        80
  56.  
  57. // ------------------------------------ struct typedefs
  58.  
  59. typedef struct {
  60.     char   searchkey[20];
  61.     char   format[3];
  62.     char   pmarkers[10];
  63.     char   smarkers[10];
  64.     int    min;
  65.     int    paraspace;
  66.     int    keep;
  67.     int    text;
  68.     int    inherit;
  69.     int    allpara;
  70.     int    width;
  71.     } frmt;
  72.  
  73. frmt Fmt = {
  74.     "@#$%^Blb)8",
  75.             // searchkey
  76.     "l",
  77.             // left aligned
  78.     "./",
  79.             // para markers
  80.     ".?!*",
  81.             // sentence markers
  82.     4,
  83.         // minimum number of words to format justify
  84.     8,
  85.             // paragraph spacing
  86.     1,
  87.         // keep text directed formatting info
  88.     1,
  89.             // obey text directed formatting
  90.     1,
  91.             // space inherited
  92.     0,
  93.             // all lines as paragraphs
  94.     72 };
  95.             // width
  96.  
  97. typedef struct {
  98.     char    space[ MAX_LINE_LEN ];
  99.     char    param[ MAX_LINE_LEN];
  100.     int     lspace;
  101.     int     wnum;
  102.     int     restspace;
  103.     char    words  [MAX_NUM_WORDS] [MAX_WORD_SZ];
  104.     int     newp;
  105.     int     oldallpara;
  106.     int     oldinherit;
  107.     int     end;
  108.     } wdinfo;
  109.  
  110. wdinfo  Words = {
  111.     "",
  112.     "",
  113.     0,
  114.     0,
  115.     0,
  116.     "",
  117.     1,
  118.     0,
  119.     1,
  120.     0 } ;
  121.  
  122. char    buffer [MAX_LINE_LEN] = "";
  123.  
  124. // --------------------------------------------------------------
  125. int PUsage(void) {
  126.     cout << "\nText formatting version " << VERSION << endl;
  127.     cout << "send donations to Brendan Babb \n";
  128.     cout << "                  @ microbiol dept,";
  129.     cout << " Univ. Ave, UCT, Rondebosch 7700, RSA\n";
  130.     cout <<
  131. "\nUSAGE:  BFMT [options listed below]\n"
  132. "   [<{input}] [>{output}]  where input and output are filenames\n"
  133. "   [-f{type}] types are l,r,j,c,u,a\n"
  134. "   [-i{0|1}]  inherit whitespace   [-s{width}]  whitespace width\n"
  135. "   [-a{0|1}]  all lines are paragraphs\n"
  136. "   [-t{0|1}]  obey options in text       \n"
  137. "   [-k{0|1}]  keep options in text\n"
  138. "   [-({sentence delimiters}]          [-{{paragraph delimiters}]\n"
  139. "   [-w{width}]  right margin\n"
  140. "   [-m{min}]  minimum words to justify\n"
  141. "   [/u]  save previous options to default\n"
  142. "   [?|-h|-?]  display this and current defaults\n";
  143.  
  144.     return 0;
  145.     }
  146.  
  147. // --------------------------------------------------------------
  148.  
  149. int PValues()  {
  150.     cout << "\nCurrent default values :\n";
  151.     cout << setw(28) << "sentence markers " << setw(6)
  152.      <<  Fmt.smarkers;
  153.     cout << setw(28) << "paragraph markers " << setw(6)
  154.      << Fmt.pmarkers << endl;
  155.     cout << setw(28) << "paragraph spacing " << setw(6)
  156.      << Fmt.paraspace;
  157.     cout << setw(28) << "all lines as para " << setw(6)
  158.      << Fmt.allpara << endl;
  159.     cout << setw(28) << "keep param lines "  << setw(6) << Fmt.keep;
  160.     cout << setw(28) << "obey param lines "  << setw(6)
  161.      << Fmt.text << endl;
  162.     cout << setw(28) << "format " << setw(6) << Fmt.format;
  163.     cout << setw(28) << "whitespace inhertited " << setw(6)
  164.      << Fmt.inherit << endl;
  165.     cout << setw(28) << "width " << setw(6) << Fmt.width;
  166.     cout << setw(28) << "minimum words to fmt " << setw(6)
  167.      << Fmt.min << endl;
  168.     return 0;
  169.     }
  170.  
  171.  
  172. // -----------------------------------  work horses
  173.  
  174. /*
  175.     divide must divide the input buffer into as many words as it
  176.     can handle, until no more input, or until max words
  177.     or only one line if allpara
  178.     returning 1 prevents more input
  179.     its function is to set up global variables Word and buffer for
  180.     the work to be done
  181.  
  182.     if new para, must quit, the format functions
  183.     will then organize the words and spaces as need be
  184.     to check for new para must look at string of paramarkers
  185.     and pass any info they may contain to the format function.
  186.  
  187.     format sub_functions must return number words used so can
  188.     update info in words.
  189.  
  190.     update_words must return how many words left.
  191.  
  192.     will continue formating if any words left or
  193.     still input information
  194. */
  195.  
  196. // ----------------------------------------------------- now do work
  197.  
  198. int divide () {
  199.     char    temp [MAX_LINE_LEN];
  200.                     // stores space in case needed
  201.     for (unsigned int ch,i=0; isspace(ch = buffer[i]); i++) {
  202.         if (ch == '\n'|| ch == '\0') {
  203.             Words.newp = 1;
  204.             buffer[0] = '\0';       // ie just space
  205.             return 1;       // 1 means stop adding
  206.             }
  207.         temp[i] = ch;
  208.         }
  209.     if (ch == EOF) {
  210.         Words.end =1;           // must prevent
  211.                         // more input
  212.         Words.newp = 0;
  213.         buffer[0] = '\0';
  214.         return 1;
  215.         }
  216.  
  217.     if (buffer[strlen(buffer)-1] == '\n')
  218.         buffer[strlen(buffer)-1] = '\0';
  219.  
  220.     if (strchr(Fmt.pmarkers,ch)) {      // check if para marker
  221.         strcpy(Words.param, &buffer[i]);
  222.         ch = strlen(Words.param);
  223.         if (Words.param[ch-1] == '\n')
  224.             Words.param[ch-1] = '\0';
  225.         buffer[0] = '\0';
  226.         Words.newp = 1;
  227.         return 1;
  228.         }
  229.     temp[i] = '\0';                         // make sure space
  230.                         // is terminated
  231.     if (Words.newp || Fmt.allpara) strcpy(Words.space, temp);
  232.  
  233. // -------------------------------- extract words
  234.  
  235.     int w_ctr;                              // internal word counter
  236.                         // Words.wnum = #words
  237.                         // j is position marker
  238.  
  239.     for (int j=i; j < strlen(buffer); j++) {
  240.         w_ctr = 0;
  241.         if (buffer[j] == EOF) {
  242.             Words.end = 1;
  243.             break;
  244.             }
  245.         if (isspace(buffer[j])) continue;
  246.                         // ignore space
  247.         while (!isspace(ch=buffer[j])) {
  248.             Words.words [Words.wnum][w_ctr] = ch;
  249.             j++;
  250.             w_ctr++;
  251.             }
  252.                         // one complete word fnd
  253.  
  254.         Words.words [Words.wnum] [w_ctr] = '\0';
  255.  
  256.                         // check if is a sentence
  257.         if (strchr(Fmt.smarkers,buffer[j-1])) {
  258.             Words.words [Words.wnum] [w_ctr] = ' ';
  259.             Words.words [Words.wnum] [w_ctr+1] = '\0';
  260.             }
  261.  
  262.         if (strlen(Words.words[Words.wnum])) Words.wnum++;
  263.  
  264.         if (buffer[j] == '\0' )
  265.             break;
  266.  
  267.         if (buffer[j] == EOF) {
  268.             Words.end = 1;
  269.             break; }
  270.  
  271.         }
  272.     Words.newp = 0;
  273.     strcpy(temp, &buffer[i]);
  274.     strcpy(buffer,temp);
  275.  
  276.     if (Fmt.allpara) return 1;
  277.     if (Words.wnum >= (MAX_NUM_WORDS) - (WNUM_OFFSET))
  278.         return 1;
  279.     return Words.newp;
  280.     }
  281.  
  282. // ------------------------------------------- space calc
  283.                         // assumes tab = 8
  284. int Calc_space_len() {
  285.     int pos = 0;
  286.     for (int i=0, s_ptr = 0; i < strlen(Words.space) ; i++) {
  287.         if (Words.space[s_ptr] == '\t')
  288.             pos = pos | 7;
  289.         else Words.space[s_ptr] = ' ';
  290.         pos++;
  291.         }
  292.     Words.lspace = pos;
  293.     return 0;
  294.     }
  295.  
  296. // --------------------------------------- update words list
  297.  
  298. int update_words(int nwords) {   // nword = words used
  299.     char temp [MAX_WORD_SZ];
  300.     for (int num = nwords ; num < Words.wnum ; num++) {
  301.         strcpy(temp, Words.words[num]);
  302.         strcpy(Words.words[num - nwords], temp);
  303.         }
  304.     Words.wnum = Words.wnum - nwords ;
  305.     if (Words.wnum < 0) Words.wnum = 0;
  306.     return 0;
  307.     }
  308.  
  309.  
  310. // ------------------------------------------------- MAX words
  311.  
  312. int Max_words_wid(int stnum) {
  313.     int num = 0;
  314.     int width;
  315.     if (Fmt.inherit) width = Words.lspace;
  316.     else width = Fmt.paraspace;
  317.     for (int i=stnum; i< Words.wnum; i++) {
  318.     if ((width + strlen(Words.words[i])) < Fmt.width) {
  319.         width += 1 + strlen(Words.words[i]);
  320.         num++;
  321.         }
  322.     else
  323.         break;
  324.     }
  325.     return (num);
  326.     }
  327.  
  328. // -------------------------------------------   format setup
  329.  
  330. int Fmt_setup() {
  331.     Words.oldallpara = Fmt.allpara;
  332.     Words.oldinherit = Fmt.inherit;
  333.     if (!strcmp(Fmt.format,"a")) {
  334.         Fmt.allpara = 1;
  335.         Fmt.inherit = 0;
  336.         Words.restspace = 0;
  337.         }
  338.  
  339.     if (!strcmp(Fmt.format,"u")) {
  340.         Fmt.allpara = 1;
  341.         Fmt.inherit = 1;
  342.         }
  343.  
  344.     if (Fmt.width < (MIN_WIDTH)) Fmt.width = MIN_WIDTH +1;
  345.  
  346.     return 0;
  347.     }
  348.  
  349. //-------------------------------------------------    format output
  350.  
  351. int fmt_out(char *b, int ws = -1) {
  352.     char temp[MAX_SP];
  353.  
  354.     if (cin.eof()) Words.end = 1;
  355.     for (int i = 0; i< MAX_SP; i++)
  356.         temp[i] = ' ';
  357.     if (ws == -1)   {
  358.             if (!Fmt.inherit) temp[Fmt.paraspace] = '\0';
  359.             else strcpy(temp, Words.space);
  360.             }
  361.     else        {
  362.             if (ws>=0&&ws<80) temp[ws] = '\0';
  363.             else ws = Fmt.paraspace;
  364.             }
  365.  
  366.     if (b&&Words.wnum) {
  367.         cout  << temp << b << endl;
  368.         }
  369.  
  370.     return 0;
  371.     }
  372.  
  373. // ------------------------------------------  print parameters
  374.  
  375. int fmt_prm() {
  376.     if (Fmt.keep) {
  377.         cout << Words.param;
  378.         }
  379.     if (!Words.end)
  380.         if (Words.newp) cout << endl;
  381.     return 0;
  382.     }
  383.  
  384. // -------------------------------------------    left fmt
  385.  
  386. int fmt_left () {
  387.     int wnum = 0;
  388.     int nword;
  389.     do {
  390.         nword = Max_words_wid(wnum);
  391.         strcpy(buffer,"");
  392.         for (int i= 0; i < nword; wnum++, i++) {
  393.             strcat(buffer, Words.words[wnum]);
  394.             strcat(buffer, " \0");
  395.             }
  396.         buffer[strlen(buffer)-1] = '\0';
  397.  
  398.         if (nword == 0 && Words.wnum) {
  399.             strcpy(buffer, Words.words[wnum]);
  400.             wnum++;
  401.             }
  402.  
  403.         fmt_out(buffer);
  404.  
  405.  
  406.         if (Words.wnum - wnum<1) break;
  407.     } while ( Words.newp ||
  408.     Words.wnum - wnum >= WNUM_OFFSET || Words.end) ;
  409.     fmt_prm();
  410.     return (wnum);
  411.     }
  412.  
  413. //-------------------------------------------------       unchanged fmt
  414.  
  415. int fmt_unchanged() {
  416.     int i = strlen(buffer)-1;
  417.     if (buffer[i] == '\n')
  418.         buffer[i] = '\0';
  419.     fmt_out(buffer);
  420.     fmt_prm();
  421.     return (Words.wnum);
  422.     }
  423.  
  424. //-------------------------------------------------       right fmt
  425. int fmt_right () {
  426.     int nword, space, wnum = 0;
  427.     do {
  428.         nword = Max_words_wid(wnum);
  429.         buffer[0] = '\0';
  430.         for (int i= 0; i < nword; wnum++, i++) {
  431.             strcat(buffer, Words.words[wnum]);
  432.             strcat(buffer, " ");
  433.             }
  434.         space = strlen(buffer)-1;
  435.         buffer[space] = '\0';
  436.         if (buffer[space-1] == ' ') {
  437.             buffer[space-1] = '\0';
  438.             space--; }
  439.  
  440.         if (nword == 0 && Words.wnum) {
  441.             strcpy(buffer, Words.words[wnum]);
  442.             wnum++;
  443.             }
  444.  
  445.         fmt_out(buffer,Fmt.width-space);
  446.  
  447.         if (Words.wnum - wnum<1) break;
  448.     } while ( Words.newp || Words.wnum - wnum >= WNUM_OFFSET) ;
  449.     fmt_prm();
  450.     return (wnum);
  451.     }
  452. //-------------------------------------------------      adjust fmt
  453.  
  454. // this needs each line to be dealt seperately
  455. // set up fmt so that allpara = 1, space =0 - not inherited;
  456. // also uses Words.restspace to keep track of where is.
  457.  
  458. int fmt_adjust() {
  459.     int space = Fmt.paraspace + Words.restspace;
  460.     if (Words.words[0][0] == '#'||Words.words[0][0] == '/')
  461.         space = 0;
  462.     if (space <0) space = 0;
  463.     if (buffer[strlen(buffer)-1] == '\n')
  464.         buffer[strlen(buffer)-1] = '\0';
  465.     fmt_out(buffer, space);
  466.  
  467.     if (strchr(buffer,'{'))
  468.         Words.restspace +=  8;
  469.     if (strchr(buffer,'}'))
  470.         Words.restspace -=  8;
  471.     if (Words.restspace <0) Words.restspace = 0;
  472.     fmt_prm();
  473.     return (Words.wnum);
  474.     }
  475. //-------------------------------------------------      centre fmt
  476.  
  477. int fmt_centre () {
  478.     int wnum, nword, cw;
  479.     nword = cw =wnum = 0;
  480.     do {
  481.         nword = Max_words_wid(wnum);
  482.         buffer[0] = '\0';
  483.         for (int i= 0; i < nword; wnum++, i++) {
  484.             strcat(buffer, Words.words[wnum]);
  485.             strcat(buffer, " ");
  486.             }
  487.         buffer[strlen(buffer)-1] = '\0';
  488.         if (Fmt.inherit) cw = - Words.lspace;
  489.         else cw = - Fmt.paraspace;
  490.         cw += Fmt.width - strlen(buffer);
  491.         cw /= 2;
  492.         if (Fmt.inherit) cw += Words.lspace;
  493.         else cw += Fmt.paraspace;
  494.  
  495.         if (nword == 0 && Words.wnum) {
  496.             strcpy(buffer, Words.words[wnum]);
  497.             wnum++;
  498.             }
  499.  
  500.         fmt_out(buffer, cw);
  501.  
  502.         if (Words.wnum - wnum<1) break;
  503.     } while ( Words.newp || Words.wnum - wnum >= WNUM_OFFSET) ;
  504.     fmt_prm();
  505.     return (wnum);
  506.     }
  507.  
  508. //-------------------------------------------------    justify text
  509.  
  510. int fmt_just () {
  511.     int wnum, nword, cw, wc, offset, rnum;
  512.     nword = cw =wnum = wc = offset = 0;
  513.     char spaces [WNUM_OFFSET] [MAX_LINE_LEN];
  514.     time_t t;
  515.  
  516.     srand((unsigned) time(&t));
  517.     do {
  518.         buffer[0] = '\0';
  519.         nword = Max_words_wid(wnum);
  520.         cw = 0;
  521.  
  522.         if (Words.newp && nword+wnum == Words.wnum)
  523.             {
  524.                for (int i= 0; i < nword; wnum++, i++) {
  525.                    strcat(buffer, Words.words[wnum]);
  526.                    strcat(buffer, " ");
  527.                    }
  528.                buffer[strlen(buffer)-1] = '\0';
  529.                }
  530.         else if (nword >= Fmt.min) {
  531.                for (int i=0; i < nword; i++) {
  532.                    wc = wnum + i;
  533.                    strcpy(spaces[i], " ");
  534.                    cw += strlen(Words.words[wc]) + 1;
  535.                    }
  536.  
  537.                if (Fmt.inherit) offset = - Words.lspace;
  538.                else offset = - Fmt.paraspace;
  539.                offset += Fmt.width  - cw + 1;
  540.                     // if last word is end sentence
  541.                if ((strchr(Words.words[wc],' '))) {
  542.                    offset++;
  543.                    cw = strlen(Words.words[wc])-1;
  544.                    Words.words[wc] [cw] = '\0';
  545.                    }
  546.  
  547.                for (i=0; i < offset; i++) {
  548.                    rnum = rand() % (nword-1);
  549.                    strcat(spaces[rnum]," ");
  550.                    }
  551.                spaces[nword-1][0] = '\0';
  552.                for (i=0; i < nword; wnum++, i++) {
  553.                    strcat(buffer,Words.words[wnum]);
  554.                    strcat(buffer,spaces[i]);
  555.                    }
  556.                }
  557.         else
  558.                {
  559.                for (int i= 0; i < nword; wnum++, i++) {
  560.                    strcat(buffer, Words.words[wnum]);
  561.                    strcat(buffer, " ");
  562.                    }
  563.                buffer[strlen(buffer)-1] = '\0';
  564.                }
  565.  
  566.  
  567.         if (nword == 0 && Words.wnum) {
  568.             strcpy(buffer, Words.words[wnum]);
  569.             wnum++;
  570.             }
  571.  
  572.         fmt_out(buffer);
  573.  
  574.         if (Words.wnum - wnum<1) break;
  575.     } while ( Words.newp || Words.wnum - wnum >= WNUM_OFFSET) ;
  576.     fmt_prm();
  577.     return (wnum);
  578.     }
  579.  
  580. //-------------------------------------------------    interpret paraline
  581.  
  582. int parameter_intr() {
  583.     char *p;
  584.  
  585.     if (Words.param) {
  586.         if (Fmt.text) {
  587.            if (p = strstr(Words.param, "-a")) {
  588.             Fmt.allpara = p[2] - '0';
  589.             Words.oldallpara = Fmt.allpara;
  590.             }
  591.  
  592.            if (p = strstr(Words.param, "-f")) {
  593.             Fmt.format[0] = p[2];
  594.             if (Fmt.format[0] == 'a'||Fmt.format[0] == 'u') {
  595.                 Fmt.allpara = 1;
  596.                 Fmt.inherit = 0;
  597.                 if (Fmt.format[0] == 'u') Fmt.inherit = 1;
  598.                 }
  599.             else    {
  600.                 Fmt.allpara = Words.oldallpara;
  601.                 Fmt.inherit = Words.oldinherit;
  602.                 }
  603.             }
  604.  
  605.            if (p = strstr(Words.param, "-i"))
  606.             Fmt.inherit = p[2] - '0';
  607.  
  608.            if (p = strstr(Words.param, "-k"))
  609.             Fmt.keep = p[2] - '0';
  610.  
  611.            if (p = strstr(Words.param, "-s"))
  612.             Fmt.paraspace = atoi(&p[2]);
  613.  
  614.            if (strstr(Words.param, "-h"))
  615.             PValues();
  616.  
  617.            if (p = strstr(Words.param, "-w")) {
  618.             Fmt.width = atoi(&p[2]);
  619.             if (Fmt.width < (MIN_WIDTH)) Fmt.width = MIN_WIDTH +1;
  620.             }
  621.            }
  622.         }
  623.  
  624.     return 0;
  625.     }
  626.  
  627. // -------------------------------------  save configuration
  628. int Config(char *p) {           // note no error checking
  629.     fstream file;
  630. #ifdef MSDOS
  631.     file.open(p, ios::in|ios::binary|ios::out);
  632. #else
  633.     file.open(p, ios::in|ios::out);
  634. #endif 
  635.     long    f_ptr = 0;
  636.     int     c_ptr = 0;
  637.     unsigned char ch,cb;
  638.  
  639.     if (!file) {
  640.         cout << "could not open file (" << p;
  641.         cout << ") to configure\n";
  642.         return 1;
  643.         }
  644.     while (file.get(ch)) {
  645.         f_ptr++;
  646.         cb = Fmt.searchkey[c_ptr];
  647.         if (ch == cb) c_ptr++;
  648.         else c_ptr = 0;
  649.         if (cb == 0) break ;
  650.         }
  651.     f_ptr -= strlen(Fmt.searchkey)+1;
  652.     file.seekp(f_ptr, ios::beg);
  653.     file.write(Fmt.searchkey,sizeof(frmt));
  654.     file.close();
  655.     return 0;
  656.     }
  657.  
  658. // --------------------------------------------------------------
  659.  
  660. int main(int argc,char *argv[])
  661.     {
  662.  
  663.     char Pswitch;
  664.     char *Val;
  665.     char *Name;
  666.  
  667.     Name = argv[0];
  668.  
  669.     if (argc > 1) for (argv++ ; *argv; argv++) {
  670.     char *thisArg = *argv;
  671.     if (*thisArg != '-' && *thisArg != '/')  {
  672.         PUsage();
  673.         PValues();
  674.         return 0; }
  675.     Pswitch = *(thisArg+1);
  676.         Val = thisArg+2;
  677.         switch (Pswitch) {
  678.              case 'a' :        Fmt.allpara = atoi(Val);
  679.                                break ;
  680.              case '?' :
  681.              case 'h' :        PUsage();
  682.                                PValues() ;
  683.                                return 0; 
  684.              case 'v' :        cout << "\nBrendan's format program";
  685.                                cout << " version " << VERSION;
  686.                                cout << endl;
  687.                                return 0;
  688.              case 'm' :        Fmt.min = atoi(Val);
  689.                                break ;
  690.              case 'f' :        strcpy(Fmt.format,Val);
  691.                                break ;
  692.              case 'w' :        Fmt.width = atoi(Val);
  693.                                break ;
  694.              case 'i' :        Fmt.inherit = atoi(Val);
  695.                                break ;
  696.              case 't' :        Fmt.text = atoi(Val);
  697.                                break ;
  698.              case 'k' :        Fmt.keep = atoi(Val);
  699.                                break ;
  700.              case 's' :        Fmt.paraspace = atoi(Val);
  701.                                break ;
  702.              case 'u' :        Config(Name);
  703.                                break;
  704.              case '{' :        strcpy(Fmt.pmarkers, Val);
  705.                                break ;
  706.              case '(' :        strcpy(Fmt.smarkers, Val);
  707.                                break ;
  708.              }
  709.         }
  710.  
  711. // ----------------------------------- main loop
  712.     int nwords, endinput, wd_fin;
  713.     Words.newp = 1;
  714.     Words.restspace = 0;
  715.     Fmt_setup();
  716.  
  717.     do {
  718.         endinput = nwords = 0;
  719.         do {
  720.             if (cin.eof()) {
  721.                 Words.end = 1;
  722.                 break ;
  723.                 }
  724.             cin.getline(buffer, MAX_LINE_LEN);
  725.             endinput += divide();
  726.             if (Fmt.allpara)  break;
  727.         } while (!(endinput)) ;
  728.         Calc_space_len();
  729.         switch (Fmt.format[0]) {
  730.         case 'l' :  nwords = fmt_left();
  731.                 break;
  732.         case 'r' :  nwords = fmt_right();
  733.                 break;
  734.         case 'j' :  nwords = fmt_just();
  735.                 break;
  736.         case 'c' :  nwords = fmt_centre();
  737.                 break;
  738.         case 'a' :  nwords = fmt_adjust();
  739.                 break;
  740.         case 'u' :  nwords = fmt_unchanged();
  741.                 break;
  742.             }
  743.  
  744.         wd_fin = update_words(nwords);
  745.  
  746.         parameter_intr();
  747.                 // allows text specified formatting
  748.  
  749.         buffer[0] = '\0';
  750.         Words.param[0] = '\0';
  751.     } while (!wd_fin&&!Words.end);
  752.  
  753.  
  754. // ----------------------------------- finish and close
  755.  
  756.     return 0;
  757.     }
  758.  
  759. // -------------------------------------------------------- END
  760.